package com.simple.util;

import net.sf.jsqlparser.expression.*;

import java.lang.reflect.InvocationTargetException;
import java.sql.Timestamp;

/**
 * 项目名称：foursmile-local-etl
 * 类名称：ExpressionsUtil
 * 类描述：ExpressionsUtil
 * 创建时间：2022/10/18
 *
 * @author jiangjunjie   (E-mail:jiangjunjie@foursmile001.com)
 * @version v1.0
 */
public class ExpressionsUtil {

    public static Expression getExpression(Object value) throws InvocationTargetException, IllegalAccessException {
        if (value == null) {
            return new NullValue();

        }

        if (value instanceof Long) {
            return new LongValue((Long) value);
        } else if (value instanceof Integer) {
            return new LongValue((Integer) value);
        } else if (value instanceof String) {
            return new StringValue((String) value);
        } else if (value instanceof Boolean) {
            return new LongValue((Boolean) value ? 1L : 0L);
        } else if (value instanceof Timestamp) {
            TimestampValue timestampValue = new TimestampValue();
            timestampValue.setValue((Timestamp) value);
            return timestampValue;
        } else {
            throw new RuntimeException("未知类型");
        }
    }

}
